package com.ruoyi.job.service.impl;

import java.util.List;

import com.ruoyi.common.enums.BusinessStatus;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.ExceptionUtil;
import com.ruoyi.job.domain.JobHelp;
import com.ruoyi.job.mapper.JobHelpMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.job.mapper.JobStudentMapper;
import com.ruoyi.job.domain.JobStudent;
import com.ruoyi.job.service.IJobStudentService;

/**
 * 学生帮扶Service业务层处理
 *
 * @author LYD
 * @date 2023-01-15
 */
@Service
public class JobStudentServiceImpl implements IJobStudentService {

    @Autowired
    private JobStudentMapper jobStudentMapper;
    @Autowired
    private JobHelpMapper jobHelpMapper;

    /**
     * 查询学生帮扶
     *
     * @param id 学生帮扶主键
     * @return 学生帮扶
     */
    @Override
    public JobStudent selectJobStudentById(Long id) {
        return jobStudentMapper.selectJobStudentById(id);
    }

    /**
     * 查询学生帮扶列表
     *
     * @param jobStudent 学生帮扶
     * @return 学生帮扶
     */
    @Override
    public List<JobStudent> selectJobStudentList(JobStudent jobStudent) {
        return jobStudentMapper.selectJobStudentList(jobStudent);
    }

    /**
     * 新增学生帮扶
     *
     * @param jobStudent 学生帮扶
     * @return 结果
     */
    @Override
    public int insertJobStudent(JobStudent jobStudent) {


        //添加帮扶管理信息
        JobHelp jobHelp = new JobHelp();
        BeanUtils.copyProperties(jobStudent,jobHelp);
        jobHelpMapper.insertJobHelp(jobHelp);

        //父类方法-添加学生帮扶信息
        return jobStudentMapper.insertJobStudent(jobStudent);
    }

    /**
     * 修改学生帮扶
     *
     * @param jobStudent 学生帮扶
     * @return 结果
     */
    @Override
    public int updateJobStudent(JobStudent jobStudent) {
        //修改帮扶信息
        String phone = jobStudent.getPhone();
        //通过手机号查找帮扶管理中是否有该学生
        JobHelp jobHelp = jobHelpMapper.findByPhone(phone);
        //如果没有该学生==电话号码可能有误
        if (jobHelp==null){
            throw new BaseException("请核对电话号码后重试，若仍失败请联系管理员！");
        }else {//有该学生==修改
            JobHelp updateJobHelp = new JobHelp();
            BeanUtils.copyProperties(jobStudent,updateJobHelp);
            updateJobHelp.setId(jobHelp.getId());
            jobHelpMapper.updateJobHelp(updateJobHelp);
        }
        //父类方法-修改学生帮扶信息
        return jobStudentMapper.updateJobStudent(jobStudent);

    }

    /**
     * 批量删除学生帮扶
     *
     * @param ids 需要删除的学生帮扶主键
     * @return 结果
     */
    @Override
    public int deleteJobStudentByIds(Long[] ids) {
        return jobStudentMapper.deleteJobStudentByIds(ids);
    }

    /**
     * 删除学生帮扶信息
     *
     * @param id 学生帮扶主键
     * @return 结果
     */
    @Override
    public int deleteJobStudentById(Long id) {
        return jobStudentMapper.deleteJobStudentById(id);
    }



}
